package com.bawei.lookfor2204a.view.activity

import androidx.fragment.app.FragmentPagerAdapter
import com.bawei.lookfor2204a.R
import com.bawei.lookfor2204a.base.BaseViewActivity
import com.bawei.lookfor2204a.databinding.ActivityMainBinding
import com.bawei.lookfor2204a.view.fragment.BangDanFragment
import com.bawei.lookfor2204a.view.fragment.FuJinFragment
import com.bawei.lookfor2204a.view.fragment.guanchang.GuangChangFragment
import com.bawei.lookfor2204a.view.fragment.WoDeFragment
import com.bawei.lookfor2204a.view.fragment.zhibo.ZhiBoFragment

/**
 * 主页面
 */
class MainActivity : BaseViewActivity<ActivityMainBinding>(R.layout.activity_main) {

    override fun initData() {

    }

    override fun initView() {
        // 标题
        binding.tvTitle.text = "LookFor"


        // 创建Fragment容器
        var list = listOf(
            GuangChangFragment(),
            FuJinFragment(),
            ZhiBoFragment(),
            BangDanFragment(),
            WoDeFragment()
        )

        // 给View Pager设置设置适配器
        binding.vp.adapter = object : FragmentPagerAdapter(supportFragmentManager) {

            // 返回有多少个页面
            override fun getCount() = list.size

            // 返回对应位置的Fragment
            override fun getItem(position: Int) = list[position]

            override fun getPageTitle(position: Int) = listOf("广场", "附近", "", "榜单", "我的")[position]
        }

        // tabLayout 与 View Pager联动
        binding.tab.setupWithViewPager(binding.vp)
        binding.tab.getTabAt(0)?.setIcon(R.drawable.home)
        binding.tab.getTabAt(1)?.setIcon(R.drawable.home)
        binding.tab.getTabAt(3)?.setIcon(R.drawable.home)
        binding.tab.getTabAt(4)?.setIcon(R.drawable.home)

    }
}